package org.nViron.nvOrganic;

//~--- non-JDK imports --------------------------------------------------------

import org.nViron.nvData.nvDataEntity;
import org.nViron.nvParams.nvContextParamMgr.CONTEXTPARAM;
import org.nViron.nvParams.nvVizParamMgr.VIZPARAM;
import org.nViron.nvRender.nvRenderer;
import org.nViron.nvRender.nvVec3;

import traer.physics.Vector3D;

/**
 * Base of an organic. Static but a Kinetic
 * @author Roland Haring <p>
 * <script type="text/javascript" src="http://www.ohloh.net/p/376434/widgets/project_basic_stats.js"></script>
 */
public class nvRoot extends nvKinetic {
    private final nvStem stem;

    public nvRoot(nvOrganic organic) {
        super(organic, null);
        particle = getOrganic().generateParticle(this);
        stem     = new nvStem(organic, this);
    }

    @Override
    public void addEntity(nvDataEntity entity) {
        stem.addEntity(entity);
    }

    @Override
    public void degenerate() {
        stem.degenerate();
    }

    @Override
    protected boolean doneDegenerating() {
        return true;
    }

    @Override
    protected boolean doneSprouting() {
        return true;
    }

    @Override
    public nvVec3 getCurrentRenderPos() {
        nvVec3 pos = getOrganic().getCurrentRenderPos();

        pos.mul(1.0f / getOrganic().getScale());

        return pos;
    }

    @Override
    public Vector3D getInitialVelocity() {
        return new Vector3D();    // does not have one
    }

    @Override
    protected int getNumChildren() {
        return 1;
    }

    @Override
    public int getNumEntities() {
        return stem.getNumEntities();
    }

    public float getSimilarityTo(nvDataEntity entity) {
        return stem.getSimilarityTo(entity);
    }

    public float getSimilarityTo(nvDataEntity other, CONTEXTPARAM contextParam) {
        return stem.getSimilarityTo(other, contextParam);
    }

    public float getSimilarityTo(nvDataEntity other, VIZPARAM vizParam) {
        return stem.getSimilarityTo(other, vizParam);
    }

    public nvStem getStem() {
        return stem;
    }

    @Override
    public float getVizValue(VIZPARAM param) {
        return stem.getVizValue(param);
    }

    @Override
    public void remove() {
        stem.remove();
        super.remove();
    }

    @Override
    public boolean removeEntity(nvDataEntity entity) {
        return stem.removeEntity(entity);
    }

    public void render(nvRenderer renderer) {
        if (!isRenderable()) {
            return;
        }

        renderer.renderRoot(this);
        stem.render(renderer);
    }

    @Override
    protected void setSelection(boolean b) {
        super.setSelection(b);

        // recursivly
        if (stem != null) {
            stem.setSelection(b);
        }
    }

    @Override
    public void update(float timeStep) {
        super.update(timeStep);
        stem.update(timeStep);
        updateStateRelativeToChild(stem);
    }

    @Override
    public void updateVizValue(VIZPARAM param) {
        stem.updateVizValue(param);
    }
}



